# définition des variables
#https://github.com/tanzilli/playground/blob/master/c/daisy7/

#PATH:=$(TOPDIR)/build/util:$(TOOLPATH)/bin:$(TOPDIR)/linux:$(TOPDIR)/build:$(BOOTLOADERDIR)/ecos/tools/bin:`pwd`:${PATH}

#CC=arm-linux-gnueabi-gcc  
CC = gcc

ifeq ($(DEBUG),1)
	CFLAGS += -g3 -O0
else
	#CFLAGS += -O3
endif

WARNINGS = -Wall
CFLAGS += $(WARNINGS)
LDFLAGS = -lrt -lm -lpthread 

# définition des paths
EXEC=DRONE
DIR_EXEC=./bin

DIR_OBJ=./obj
DIR_OBJ_SENSORS=$(DIR_OBJ)/sensors
DIR_OBJ_DRIVERS=$(DIR_OBJ)/drivers

DIR_SRC=./src
DIR_SRC_SENSORS=$(DIR_SRC)/sensors
DIR_SRC_DRIVERS=$(DIR_SRC)/drv


# définition des cibles particulières
.PHONY: clean

  
# désactivation des règles implicites
.SUFFIXES:
  
  
# all
all: 	main.o drivers.o sensors.o 
	$(CC) $(DIR_OBJ)/main.o 			\
		$(DIR_OBJ_SENSORS)/sensors.o 		\
		$(DIR_OBJ_SENSORS)/bmp085.o 		\
		$(DIR_OBJ_SENSORS)/hmc5883l.o 		\
		$(DIR_OBJ_SENSORS)/l3g4200.o 		\
		$(DIR_OBJ_SENSORS)/venus638.o 		\
		$(DIR_OBJ_SENSORS)/stlis331dlh.o 	\
		$(DIR_OBJ_DRIVERS)/drv_gpio.o 		\
		$(DIR_OBJ_DRIVERS)/drv_adc.o 		\
		$(DIR_OBJ_DRIVERS)/drv_i2c.o 		\
		$(DIR_OBJ_DRIVERS)/drv_servo.o 		\
		$(DIR_OBJ_DRIVERS)/drv_timer.o 		\
		$(DIR_OBJ_DRIVERS)/drv_leds.o 		\
		$(DIR_OBJ_DRIVERS)/drv_uart.o 		\
		$(DIR_OBJ_DRIVERS)/drv_socket.o 	\
		-o $(DIR_EXEC)/$(EXEC) $(LDFLAGS) 	
	#scp $(DIR_EXEC)/$(EXEC) pi@10.10.22.223:/home/pi/
	#scp $(DIR_EXEC)/$(EXEC) root@10.10.22.223:/home
	#scp $(DIR_EXEC)/$(EXEC) root@192.168.0.28:/home
	
  
main.o: 
	$(CC) -c $(DIR_SRC)/main.c -o $(DIR_OBJ)/main.o
  
sensors.o: 	
	$(CC) -c $(DIR_SRC_SENSORS)/sensors.c -o $(DIR_OBJ_SENSORS)/sensors.o $(CFLAGS)
	$(CC) -c $(DIR_SRC_SENSORS)/bmp085.c -o $(DIR_OBJ_SENSORS)/bmp085.o $(CFLAGS)
	$(CC) -c $(DIR_SRC_SENSORS)/hmc5883l.c -o $(DIR_OBJ_SENSORS)/hmc5883l.o $(CFLAGS)
	$(CC) -c $(DIR_SRC_SENSORS)/l3g4200.c -o $(DIR_OBJ_SENSORS)/l3g4200.o $(CFLAGS)
	$(CC) -c $(DIR_SRC_SENSORS)/venus638.c -o $(DIR_OBJ_SENSORS)/venus638.o $(CFLAGS)
	$(CC) -c $(DIR_SRC_SENSORS)/stlis331dlh.c -o $(DIR_OBJ_SENSORS)/stlis331dlh.o $(CFLAGS)
  
drivers.o:
	$(CC) -c $(DIR_SRC_DRIVERS)/drv_socket.c -o $(DIR_OBJ_DRIVERS)/drv_socket.o $(CFLAGS)
	$(CC) -c $(DIR_SRC_DRIVERS)/drv_uart.c -o $(DIR_OBJ_DRIVERS)/drv_uart.o $(CFLAGS)
	$(CC) -c $(DIR_SRC_DRIVERS)/drv_leds.c -o $(DIR_OBJ_DRIVERS)/drv_leds.o $(CFLAGS)
	$(CC) -c $(DIR_SRC_DRIVERS)/drv_timer.c -o $(DIR_OBJ_DRIVERS)/drv_timer.o $(CFLAGS)
	$(CC) -c $(DIR_SRC_DRIVERS)/drv_gpio.c -o $(DIR_OBJ_DRIVERS)/drv_gpio.o $(CFLAGS)
	$(CC) -c $(DIR_SRC_DRIVERS)/drv_adc.c -o $(DIR_OBJ_DRIVERS)/drv_adc.o $(CFLAGS)
	$(CC) -c $(DIR_SRC_DRIVERS)/drv_i2c.c -o $(DIR_OBJ_DRIVERS)/drv_i2c.o $(CFLAGS)
	$(CC) -c $(DIR_SRC_DRIVERS)/drv_servo.c -o $(DIR_OBJ_DRIVERS)/drv_servo.o $(CFLAGS)
  
# clean
clean:
	rm -rf *.o
  
# clear
clear: clean
	rm -rf $(DIR_OBJ)/*.o
	rm -rf $(DIR_OBJ_SENSORS)/*.o
	rm -rf $(DIR_OBJ_DRIVERS)/*.o
	rm -rf $(DIR_EXEC)/$(EXEC)
	
# install
install: 
	./bin/DRONE




